﻿using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using MQCommon;
using MQCommon.Model;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace OrderServices.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly ICapPublisher capPublisher;
        public OrdersController(ICapPublisher capPublisher)
        {
            this.capPublisher = capPublisher;
        }
        // GET: api/<OrdersController>
        [Route("ctreatUser")]
        [NonAction]
        [CapSubscribe("order.createorder")]
        public ActionResult<Order> ctreatUser(Order od, [FromCap] CapHeader header)
        {
            var token = header["token"];
            DapperHelper dh = new DapperHelper();
            dh.BeginTransaction(() => {
                dh.Execute($"insert into Order values({od.Id},'{od.Title}','{od.ctreattime}','{od.userid}')");
            }, capPublisher);
            return Content("OK");
        }
    }
}
